home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / cardpkg_1.3.lha / CardPkg / Cards.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  2.6 KB  |  118 lines

  1. /************************************************************
  2.  
  3.     TML's C Language Card Image Package  v1.1
  4.     January, 1993
  5.     Todd M. Lewis             (919) 776-7386
  6.     2601 Piedmont Drive
  7.     Sanford, NC  27330-9437
  8.     USA
  9. ************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include "Cards.h"
  13.  
  14. BOOL CardColorSwapping = TRUE;
  15.  
  16. BOOL ValidCardID( CardID_t card )
  17.   {
  18.     BOOL retcode = FALSE;
  19.     UWORD suit, rank;
  20.     rank = card & 0x0ff;
  21.     suit = card >> 8;
  22.     switch ( suit )
  23.       {
  24.         case SUIT_SPADES   :
  25.         case SUIT_CLUBS    :
  26.         case SUIT_DIAMONDS :
  27.         case SUIT_HEARTS   : if ( rank > 0 && rank < 14 )
  28.                                 retcode = TRUE;
  29.                              break;
  30.         case SUIT_SPECIAL  : if ( rank > 0 && rank < 5 )
  31.                                 retcode = TRUE;
  32.                              break;
  33.         default            : retcode = FALSE;
  34.                              break;
  35.       }
  36.     return retcode;
  37.   }
  38.  
  39. CardID_t CardID( UWORD Suit, UWORD Rank )
  40.   {
  41.     CardID_t card = 0;
  42.  
  43.     card = (Suit << 8) | Rank;
  44.     if ( ValidCardID( card ) )
  45.         return card;
  46.       else
  47.         return 0;
  48.   }
  49.  
  50. UWORD CardSuit( CardID_t id )
  51.   {
  52.     UWORD suit;
  53.     if ( ValidCardID( id ) )
  54.         suit = id >> 8;
  55.       else
  56.         suit = 0;
  57.     return suit;
  58.   }
  59.  
  60. UWORD CardRank( CardID_t id )
  61.   {
  62.     UWORD rank;
  63.     if ( ValidCardID( id ) )
  64.         rank = id & 0x0ff;
  65.       else
  66.         rank = 0;
  67.     return rank;
  68.   }
  69.  
  70. BOOL CardRange( CardID_t *where, UWORD count, UWORD offset, UWORD suit, UWORD rank )
  71.   {
  72.     if ( !ValidCardID( CardID(suit, rank) ) )
  73.       return FALSE;
  74.  
  75.     if ( suit == SUIT_SPECIAL )
  76.         {
  77.           while ( count )
  78.             {
  79.               *where = CardID( suit, rank );
  80.               where = where + offset/sizeof(CardID_t);
  81.               count--;
  82.               rank = (rank % 4 ) + 1;
  83.             }
  84.         }
  85.       else
  86.         {
  87.           while ( count )
  88.             {
  89.               *where = CardID( suit, rank );
  90.               where = where + offset/sizeof(CardID_t);
  91.               count--;
  92.               rank = (rank % 13 ) + 1;
  93.               if (rank == 1)
  94.                 suit = ( suit % 4 ) + 1;
  95.             }
  96.         }
  97.     return TRUE;
  98.   }
  99.  
  100. extern ULONG RangeRand( ULONG );
  101.  
  102. void Shuffle( CardID_t *where, UWORD count, UWORD offset )
  103.   {
  104.     ULONG i;
  105.     CardID_t ci;
  106.     CardID_t *wi, *wj;
  107.  
  108.     for (i=0; i<count; i++)
  109.       {
  110.         wi = where + i                  * offset/sizeof(CardID_t);
  111.         wj = where + RangeRand( count ) * offset/sizeof(CardID_t);
  112.         ci = *wi;
  113.              *wi = *wj;
  114.                    *wj = ci;
  115.       }
  116.   }
  117.  
  118.